const express = require('express');
const router = express.Router();
const adminUserController = require('../controllers/adminUserController');
const { authenticateAdmin } = require('../middleware/auth');
const { adminLogger } = require('../middleware/adminLogger');

// 所有接口都需要管理员权限
router.use(authenticateAdmin);

// 获取所有用户
router.get('/', adminUserController.getAllUsers);

// 获取用户详情
router.get('/:id', adminUserController.getUserDetail);

// 创建用户
router.post(
  '/',
  adminLogger('create_user', (req) => `创建用户: ${req.body.phone}`),
  adminUserController.createUser
);

// 更新用户信息
router.put(
  '/:id',
  adminLogger('update_user', (req) => `更新用户ID: ${req.params.id}`),
  adminUserController.updateUser
);

// 重置用户密码
router.post(
  '/:id/reset-password',
  adminLogger('reset_password', (req) => `重置用户密码，ID: ${req.params.id}`),
  adminUserController.resetUserPassword
);

// 删除用户
router.delete(
  '/:id',
  adminLogger('delete_user', (req) => `删除用户ID: ${req.params.id}`),
  adminUserController.deleteUser
);

// 获取用户借阅历史
router.get('/:id/borrow-history', adminUserController.getUserBorrowHistory);

// 获取用户统计
router.get('/stats/overview', adminUserController.getUserStats);

module.exports = router;

